package de.roon.weighttracker;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import de.roon.weighttracker.db.DBHelper;
import de.roon.weighttracker.db.Weights;

public class AddWeight extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_edit_weight);
		ActionBar actionBar = getActionBar();
	    actionBar.setDisplayHomeAsUpEnabled(true);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_edit_weight, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// React on Options Menu clicked
		Intent returnIntent = new Intent();
		switch (item.getItemId()) {
		case R.id.menu_aw_save:
			saveWeight();
			finish();
		case R.id.menu_aw_cancel:
			setResult(RESULT_CANCELED, returnIntent);        
			finish();
		case android.R.id.home:
			setResult(RESULT_CANCELED, returnIntent);        
			finish();
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onBackPressed() {
		Intent returnIntent = new Intent();
		setResult(RESULT_CANCELED, returnIntent); 
		finish();
	}
	
	public void saveWeight() {
		DBHelper db = new DBHelper(this);

        // Inserting Weight
        db.addWeight(new Weights(R.id.edit_date, R.id.edit_entry_weight, R.id.edit_bmi));
	}
	
	
	
}
